# -*- coding: utf-8 -*- 
from django.http import HttpResponse
from django.template import Template, Context
from django.template.context import RequestContext 
from django.shortcuts import render_to_response
from jf.db.connection import *	
from jf.db.api.get_reference import *
from jf.db.api.log import *
from jf.volia.models import *
import cx_Oracle

def tt(request):
    return render_to_response('index.html',{'type':'typ1e'})

def get(request):
    connec = connect("ic_racs_work", "ic_racs_work", "dev10gse")
    cursor = connec.cursor() 
    time = cursor.var(cx_Oracle.DATETIME)
    cursor.execute(""" 
       begin
        select sysdate
        into :var
         from dual;
       end;
       """, var = time) 

    ret = ref_operations(connec)
    return render_to_response('get.html',{'current_date':time.getvalue(),'ro': get_top_sql(connec) })

def post(request):
    query = request.POST.get('log', '')
#    connec = connect("ic_racs_work", "ic_racs_work", "dev10gse")
    connec = connect("catalog_viewer", "catalog_viewer", "dev10gse")
#    test_log(connec, query)
    get_top_sql(connec)
    return render_to_response('get.html',{'current_date':'Saved!'+query })   

def register(request):
    country = Country()
    hot = Hotel()
    country.Name = request.POST.get('Country', '')
    country.save()
    hot.Name = request.POST.get('Name', '')
    hot.Type = request.POST.get('Type', '')
    hot.Country = country
    hot.City = request.POST.get('City', '')
    hot.open_date = '2010-12-12'    
    hot.save()
    return render_to_response('register.html',{'current_date':'Saved!','hotel_list':Hotel.objects.all()})

def get_hotel(request):
    if request.method == "POST":
        hot = Hotel.objects.filter(Name=request.POST.get('Name', ''))
    else:
	    hot = Hotel.objects.filter(Name=request.GET.get('Name', ''))
    return render_to_response('register.html',{'current_date':'Saved!','hotel_list':hot})
